﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Mvc;
using GWEB.WebBase.Data;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;
using Newtonsoft.Json;

namespace GWEB.WebFrame.Contract
{
    public class CarriedController : PageInfoBase
    {

        [ActionFilter(IsLogin = true)]
        public ActionResult Index(String id, String keyCode)
        {
            return Load("Carried", "Contract/Carried", id, keyCode);
        }
        protected override SqlState SqlExecute(BaseData bd, string id, Dictionary<string, object> data)
        {

//            String userId = BasePage.GetUserId(Session);
//            string Remark = data["Remark"].ToString();
//            data.Remove("Remark");
//            data["status"] = "4";
//            String[] sqls = new string[2];
//            //延时日志
//            sqls[0] = String.Format(@"insert into Cu_Contract_Delay(ContractId,OldCourseEnd,NewCourseEnd,CreateId,Remark,CreateDate)
//select id, CourseEnd, '{0}', {1},'{3}', getdate() from cu_Contract where id = {2}", Fun.cSql(data["CourseEnd"]), userId, id, Remark);


            String[] sql = new String[3];
            sql[0] = "update cu_Contract set CourseStart='" + data["CourseStart"] + "',CourseEnd=DATEADD(DAY,DATEDIFF(day,constart,conend),'" + data["CourseStart"] + "'),status=3 where id=" + id;
            sql[1] = "update cu_Customers set ContractId='" + id + "' where id =(select Cid from cu_Contract where id=" + id + ")";
            sql[2] = "update cu_TeacherCourse_sign set ContractId='" + id + "' where Cid =(select Cid from cu_Contract where id=" + id + ")";

            //sqls[1] = BaseData.MapToSql("cu_Contract", "id", id, data);
            bool t = bd.ExecuteSQL(sql);
            return t ? SqlState.True : SqlState.False;
        }
    }
}